home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / ddj0492.zip / DFLT11.ZIP / MEMOPAD.C < prev    next >
Text File  |  1992-02-18  |  19KB  |  621 lines

  1. /* --------------- memopad.c ----------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. extern DBOX PrintSetup;
  6.  
  7. char DFlatApplication[] = "MemoPad";
  8.  
  9. static char Untitled[] = "Untitled";
  10. static int wndpos;
  11.  
  12. static int MemoPadProc(WINDOW, MESSAGE, PARAM, PARAM);
  13. static void NewFile(WINDOW);
  14. static void SelectFile(WINDOW);
  15. static void PadWindow(WINDOW, char *);
  16. static void OpenPadWindow(WINDOW, char *);
  17. static void LoadFile(WINDOW);
  18. static void PrintPad(WINDOW);
  19. static void SaveFile(WINDOW, int);
  20. static void DeleteFile(WINDOW);
  21. static int EditorProc(WINDOW, MESSAGE, PARAM, PARAM);
  22. static char *NameComponent(char *);
  23. static int PrintSetupProc(WINDOW, MESSAGE, PARAM, PARAM);
  24. static void FixTabMenu(void);
  25. #ifndef TURBOC
  26. void Calendar(WINDOW);
  27. #endif
  28. void BarChart(WINDOW);
  29. char **Argv;
  30.  
  31. #define CHARSLINE 80
  32. #define LINESPAGE 66
  33.  
  34. void main(int argc, char *argv[])
  35. {
  36.     WINDOW wnd;
  37.     if (!init_messages())
  38.         return;
  39.     Argv = argv;
  40.     if (!LoadConfig())
  41.         cfg.ScreenLines = SCREENHEIGHT;
  42.     wnd = CreateWindow(APPLICATION,
  43.                         "D-Flat MemoPad " VERSION,
  44.                         0, 0, -1, -1,
  45.                         &MainMenu,
  46.                         NULL,
  47.                         MemoPadProc,
  48.                         MOVEABLE  |
  49.                         SIZEABLE  |
  50.                         HASBORDER |
  51.                         HASSTATUSBAR
  52.                         );
  53.  
  54.     SendMessage(wnd, SETFOCUS, TRUE, 0);
  55.     while (argc > 1)    {
  56.         PadWindow(wnd, argv[1]);
  57.         --argc;
  58.         argv++;
  59.     }
  60.     while (dispatch_message())
  61.         ;
  62. }
  63. /* ------ open text files and put them into editboxes ----- */
  64. static void PadWindow(WINDOW wnd, char *FileName)
  65. {
  66.     int ax, criterr = 1;
  67.     struct ffblk ff;
  68.     char path[64];
  69.     char *cp;
  70.  
  71.     CreatePath(path, FileName, FALSE, FALSE);
  72.     cp = path+strlen(path);
  73.     CreatePath(path, FileName, TRUE, FALSE);
  74.     while (criterr == 1)    {
  75.         ax = findfirst(path, &ff, 0);
  76.         criterr = TestCriticalError();
  77.     }
  78.     while (ax == 0 && !criterr)    {
  79.         strcpy(cp, ff.ff_name);
  80.         OpenPadWindow(wnd, path);
  81.         ax = findnext(&ff);
  82.     }
  83. }
  84. /* ------- window processing module for the
  85.                     memopad application window ----- */
  86. static int MemoPadProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  87. {
  88.     int rtn;
  89.     switch (msg)    {
  90.         case CREATE_WINDOW:
  91.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  92.             if (cfg.InsertMode)
  93.                 SetCommandToggle(&MainMenu, ID_INSERT);
  94.             if (cfg.WordWrap)
  95.                 SetCommandToggle(&MainMenu, ID_WRAP);
  96.             FixTabMenu();
  97.             return rtn;
  98.         case COMMAND:
  99.             switch ((int)p1)    {
  100.                 case ID_NEW:
  101.                     NewFile(wnd);
  102.                     return TRUE;
  103.                 case ID_OPEN:
  104.                     SelectFile(wnd);
  105.                     return TRUE;
  106.                 case ID_SAVE:
  107.                     SaveFile(inFocus, FALSE);
  108.                     return TRUE;
  109.                 case ID_SAVEAS:
  110.                     SaveFile(inFocus, TRUE);
  111.                     return TRUE;
  112.                 case ID_DELETEFILE:
  113.                     DeleteFile(inFocus);
  114.                     return TRUE;
  115.                 case ID_PRINTSETUP:
  116.                     DialogBox(wnd, &PrintSetup, TRUE, PrintSetupProc);
  117.                     return TRUE;
  118.                 case ID_PRINT:
  119.                     PrintPad(inFocus);
  120.                     return TRUE;
  121.                 case ID_EXIT:    
  122.                     if (!YesNoBox("Exit Memopad?"))
  123.                         return FALSE;
  124.                     break;
  125.                 case ID_TAB2:
  126.                     cfg.Tabs = 2;
  127.                     FixTabMenu();
  128.                     return TRUE;
  129.                 case ID_TAB4:
  130.                     cfg.Tabs = 4;
  131.                     FixTabMenu();
  132.                     return TRUE;
  133.                 case ID_TAB6:
  134.                     cfg.Tabs = 6;                    
  135.                     FixTabMenu();
  136.                     return TRUE;
  137.                 case ID_TAB8:
  138.                     cfg.Tabs = 8;
  139.                     FixTabMenu();
  140.                     return TRUE;
  141.                 case ID_CALENDAR:
  142. #ifndef TURBOC
  143.                     Calendar(wnd);
  144. #endif
  145.                     return TRUE;
  146.                 case ID_BARCHART:
  147.                     BarChart(wnd);
  148.                     return TRUE;
  149.                 case ID_ABOUT:
  150.                     MessageBox(
  151.                          "About D-Flat and the MemoPad",
  152.                         "   ┌───────────────────────┐\n"
  153.                         "   │    ▄▄▄   ▄▄▄     ▄    │\n"
  154.                         "   │    █  █  █  █    █    │\n"
  155.                         "   │    █  █  █  █    █    │\n"
  156.                         "   │    █  █  █  █ █  █    │\n"
  157.                         "   │    ▀▀▀   ▀▀▀   ▀▀     │\n"
  158.                         "   └───────────────────────┘\n"
  159.                         "D-Flat implements the SAA/CUA\n"
  160.                         "interface in a public domain\n"
  161.                         "C language library originally\n"
  162.                         "published in Dr. Dobb's Journal\n"
  163.                         "    ------------------------ \n"
  164.                         "MemoPad is a multiple document\n"
  165.                         "editor that demonstrates D-Flat");
  166.                     return TRUE;
  167.                 default:
  168.                     break;
  169.             }
  170.             break;
  171.         default:
  172.             break;
  173.     }
  174.     return DefaultWndProc(wnd, msg, p1, p2);
  175. }
  176. /* --- The New command. Open an empty editor window --- */
  177. static void NewFile(WINDOW wnd)
  178. {
  179.     OpenPadWindow(wnd, Untitled);
  180. }
  181. /* --- The Open... command. Select a file  --- */
  182. static void SelectFile(WINDOW wnd)
  183. {
  184.     char FileName[64];
  185.     if (OpenFileDialogBox("*.PAD", FileName))    {
  186.         /* --- see if the document is already in a window --- */
  187.         WINDOW wnd1 = GetFirstChild(wnd);
  188.         while (wnd1 != NULL)    {
  189.             if (stricmp(FileName, wnd1->extension) == 0)    {
  190.                 SendMessage(wnd1, SETFOCUS, TRUE, 0);
  191.                 SendMessage(wnd1, RESTORE, 0, 0);
  192.                 return;
  193.             }
  194.             wnd1 = GetNextChild(wnd, wnd1);
  195.         }
  196.         OpenPadWindow(wnd, FileName);
  197.     }
  198. }
  199.  
  200. /* --- open a document window and load a file --- */
  201. static void OpenPadWindow(WINDOW wnd, char *FileName)
  202. {
  203.     static WINDOW wnd1 = NULL;
  204.     struct stat sb;
  205.     char *Fname = FileName;
  206.     char *ermsg;
  207.     if (strcmp(FileName, Untitled))    {
  208.         if (stat(FileName, &sb))    {
  209.             if ((ermsg = malloc(strlen(FileName)+20)) != NULL) {
  210.                 strcpy(ermsg, "No such file as\n");
  211.                 strcat(ermsg, FileName);
  212.                 ErrorMessage(ermsg);
  213.                 free(ermsg);
  214.             }
  215.             return;
  216.         }
  217.         Fname = NameComponent(FileName);
  218.     }
  219.     wndpos += 2;
  220.     if (wndpos == 20)
  221.         wndpos = 2;
  222.     wnd1 = CreateWindow(EDITBOX,
  223.                 Fname,
  224.                 (wndpos-1)*2, wndpos, 10, 40,
  225.                 NULL, wnd, EditorProc,
  226.                 SHADOW     |
  227.                 MINMAXBOX  |
  228.                 CONTROLBOX |
  229.                 VSCROLLBAR |
  230.                 HSCROLLBAR |
  231.                 MOVEABLE   |
  232.                 HASBORDER  |
  233.                 SIZEABLE   |
  234.                 MULTILINE
  235.     );
  236.     if (strcmp(FileName, Untitled))    {
  237.         if ((wnd1->extension = malloc(strlen(FileName)+1)) != NULL)    {
  238.             strcpy(wnd1->extension, FileName);
  239.             LoadFile(wnd1);
  240.         }
  241.     }
  242.     SendMessage(wnd1, SETFOCUS, TRUE, 0);
  243. }
  244. /* --- Load the notepad file into the editor text buffer --- */
  245. static void LoadFile(WINDOW wnd)
  246. {
  247.     char *Buf = NULL;
  248.     int recptr = 0;
  249.     FILE *fp;
  250.  
  251.     if ((fp = fopen(wnd->extension, "rt")) != NULL)    {
  252.         WINDOW wwnd = WatchIcon();
  253.         while (!feof(fp))    {
  254.             handshake();
  255.             if ((Buf = realloc(Buf, recptr+150)) == NULL)
  256.                 break;
  257.             fgets(Buf+recptr, 150, fp);
  258.             recptr += strlen(Buf+recptr);
  259.         }
  260.         fclose(fp);
  261.         SendMessage(wwnd, CLOSE_WINDOW, 0, 0);
  262.         if (Buf != NULL)    {
  263.             SendMessage(wnd, SETTEXT, (PARAM) Buf, 0);
  264.             free(Buf);
  265.         }
  266.     }
  267. }
  268.  
  269. static int LineCtr;
  270. static int CharCtr;
  271.  
  272. /* ------- print a character -------- */
  273. static void PrintChar(FILE *prn, int c)
  274. {
  275.     int i;
  276.     if (c == '\n' || CharCtr == cfg.RightMargin)    {
  277.         fputs("\r\n", prn);
  278.         LineCtr++;
  279.         if (LineCtr == cfg.BottomMargin)    {
  280.             fputc('\f', prn);
  281.             for (i = 0; i < cfg.TopMargin; i++)
  282.                 fputc('\n', prn);
  283.             LineCtr = cfg.TopMargin;
  284.         }
  285.         CharCtr = 0;
  286.         if (c == '\n')
  287.             return;
  288.     }
  289.     if (CharCtr == 0)    {
  290.         for (i = 0; i < cfg.LeftMargin; i++)    {
  291.             fputc(' ', prn);
  292.             CharCtr++;
  293.         }
  294.     }
  295.     CharCtr++;
  296.     fputc(c, prn);
  297. }
  298.  
  299. /* --- print the current notepad --- */
  300. static void PrintPad(WINDOW wnd)
  301. {
  302.     if (*cfg.PrinterPort)    {
  303.         FILE *prn;
  304.         if ((prn = fopen(cfg.PrinterPort, "wt")) != NULL)    {
  305.             long percent;
  306.             BOOL KeepPrinting = TRUE;
  307.             unsigned char *text = GetText(wnd);
  308.             unsigned oldpct = 100, cct = 0, len = strlen(text);
  309.             WINDOW swnd = SliderBox(20, GetTitle(wnd), "Printing");
  310.             /* ------- print the notepad text --------- */
  311.             LineCtr = CharCtr = 0;
  312.             while (KeepPrinting && *text)    {
  313.                 PrintChar(prn, *text++);
  314.                 percent = ((long) ++cct * 100) / len;
  315.                 if ((int) percent != oldpct)    {
  316.                     oldpct = (int) percent;
  317.                     KeepPrinting = SendMessage(swnd, PAINT, 0, oldpct);
  318.                 }
  319.             }
  320.             if (KeepPrinting)
  321.                 /* ---- user did not cancel ---- */
  322.                 if (oldpct < 100)
  323.                     SendMessage(swnd, PAINT, 0, 100);
  324.                /* ------- follow with a form feed? --------- */
  325.                if (YesNoBox("Form Feed?"))
  326.                    fputc('\f', prn);
  327.             fclose(prn);
  328.         }
  329.         else
  330.             ErrorMessage("Cannot open printer file");
  331.     }
  332.     else
  333.         ErrorMessage("No printer selected");
  334. }
  335.  
  336. /* ---------- save a file to disk ------------ */
  337. static void SaveFile(WINDOW wnd, int Saveas)
  338. {
  339.     FILE *fp;
  340.     if (wnd->extension == NULL || Saveas)    {
  341.         char FileName[64];
  342.         if (SaveAsDialogBox(FileName))    {
  343.             if (wnd->extension != NULL)
  344.                 free(wnd->extension);
  345.             if ((wnd->extension =
  346.                     malloc(strlen(FileName)+1)) != NULL)    {
  347.                 strcpy(wnd->extension, FileName);
  348.                 AddTitle(wnd, NameComponent(FileName));
  349.                 SendMessage(wnd, BORDER, 0, 0);
  350.             }
  351.         }
  352.         else
  353.             return;
  354.     }
  355.     if (wnd->extension != NULL)    {
  356.         WINDOW mwnd = MomentaryMessage("Saving the file");
  357.         if ((fp = fopen(wnd->extension, "wt")) != NULL)    {
  358.             fwrite(GetText(wnd), strlen(GetText(wnd)), 1, fp);
  359.             fclose(fp);
  360.             wnd->TextChanged = FALSE;
  361.         }
  362.         SendMessage(mwnd, CLOSE_WINDOW, 0, 0);
  363.     }
  364. }
  365. /* -------- delete a file ------------ */
  366. static void DeleteFile(WINDOW wnd)
  367. {
  368.     if (wnd->extension != NULL)    {
  369.         if (strcmp(wnd->extension, Untitled))    {
  370.             char *fn = NameComponent(wnd->extension);
  371.             if (fn != NULL)    {
  372.                 char msg[30];
  373.                 sprintf(msg, "Delete %s?", fn);
  374.                 if (YesNoBox(msg))    {
  375.                     unlink(wnd->extension);
  376.                     SendMessage(wnd, CLOSE_WINDOW, 0, 0);
  377.                 }
  378.             }
  379.         }
  380.     }
  381. }
  382. /* ------ display the row and column in the statusbar ------ */
  383. static void ShowPosition(WINDOW wnd)
  384. {
  385.     char status[30];
  386.     sprintf(status, "Line:%4d  Column: %2d",
  387.         wnd->CurrLine, wnd->CurrCol);
  388.     SendMessage(GetParent(wnd), ADDSTATUS, (PARAM) status, 0);
  389. }
  390. /* ----- window processing module for the editboxes ----- */
  391. static int EditorProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  392. {
  393.     int rtn;
  394.     switch (msg)    {
  395.         case SETFOCUS:
  396.             if ((int)p1)    {
  397.                 wnd->InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
  398.                 wnd->WordWrapMode = GetCommandToggle(&MainMenu, ID_WRAP);
  399.             }
  400.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  401.             if ((int)p1 == FALSE)
  402.                 SendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
  403.             else 
  404.                 ShowPosition(wnd);
  405.             return rtn;
  406.         case KEYBOARD_CURSOR:
  407.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  408.             ShowPosition(wnd);
  409.             return rtn;
  410.         case COMMAND:
  411.             switch ((int) p1)    {
  412.                 case ID_SEARCH:
  413.                     SearchText(wnd);
  414.                     return TRUE;
  415.                 case ID_REPLACE:
  416.                     ReplaceText(wnd);
  417.                     return TRUE;
  418.                 case ID_SEARCHNEXT:
  419.                     SearchNext(wnd);
  420.                     return TRUE;
  421.                 case ID_CUT:
  422.                     CopyToClipboard(wnd);
  423.                     SendMessage(wnd, COMMAND, ID_DELETETEXT, 0);
  424.                     SendMessage(wnd, PAINT, 0, 0);
  425.                     return TRUE;
  426.                 case ID_COPY:
  427.                     CopyToClipboard(wnd);
  428.                     ClearTextBlock(wnd);
  429.                     SendMessage(wnd, PAINT, 0, 0);
  430.                     return TRUE;
  431.                 case ID_PASTE:
  432.                     PasteFromClipboard(wnd);
  433.                     SendMessage(wnd, PAINT, 0, 0);
  434.                     return TRUE;
  435.                 case ID_HELP:
  436.                     DisplayHelp(wnd, "MEMOPADDOC");
  437.                     return TRUE;
  438.                 case ID_WRAP:
  439.                     wnd->WordWrapMode = GetCommandToggle(&MainMenu, ID_WRAP);
  440.                     cfg.WordWrap = wnd->WordWrapMode;
  441.                     return TRUE;
  442.                 case ID_INSERT:
  443.                     wnd->InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
  444.                     cfg.InsertMode = wnd->InsertMode;
  445.                     SendMessage(NULL, SHOW_CURSOR, wnd->InsertMode, 0);
  446.                     return TRUE;
  447.                 default:
  448.                     break;
  449.             }
  450.             break;
  451.         case CLOSE_WINDOW:
  452.             if (wnd->TextChanged)    {
  453.                 char *cp = malloc(25+strlen(GetTitle(wnd)));
  454.                 SendMessage(wnd, SETFOCUS, TRUE, 0);
  455.                 if (cp != NULL)    {
  456.                     strcpy(cp, GetTitle(wnd));
  457.                     strcat(cp, "\nText changed. Save it?");
  458.                     if (YesNoBox(cp))
  459.                         SendMessage(GetParent(wnd),
  460.                             COMMAND, ID_SAVE, 0);
  461.                     free(cp);
  462.                 }
  463.             }
  464.             wndpos = 0;
  465.             if (wnd->extension != NULL)    {
  466.                 free(wnd->extension);
  467.                 wnd->extension = NULL;
  468.             }
  469.             break;
  470.         default:
  471.             break;
  472.     }
  473.     return DefaultWndProc(wnd, msg, p1, p2);
  474. }
  475. /* -- point to the name component of a file specification -- */
  476. static char *NameComponent(char *FileName)
  477. {
  478.     char *Fname;
  479.     if ((Fname = strrchr(FileName, '\\')) == NULL)
  480.         if ((Fname = strrchr(FileName, ':')) == NULL)
  481.             Fname = FileName-1;
  482.     return Fname + 1;
  483. }
  484.  
  485. static char *ports[] = {
  486.     "Lpt1",    "Lpt2",    "Lpt3",
  487.     "Com1",    "Com2",    "Com3",    "Com4",
  488.       NULL
  489. };
  490.  
  491. static int PrintSetupProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  492. {
  493.     int rtn, i = 0, mar;
  494.     char marg[10];
  495.     WINDOW cwnd;
  496.     switch (msg)    {
  497.         case CREATE_WINDOW:
  498.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  499.             PutItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort);
  500.             while (ports[i] != NULL)
  501.                 PutComboListText(wnd, ID_PRINTERPORT, ports[i++]);
  502.             for (mar = CHARSLINE; mar >= 0; --mar)    {
  503.                 sprintf(marg, "%3d", mar);
  504.                 PutItemText(wnd, ID_LEFTMARGIN, marg);
  505.                 PutItemText(wnd, ID_RIGHTMARGIN, marg);
  506.             }
  507.             for (mar = LINESPAGE; mar >= 0; --mar)    {
  508.                 sprintf(marg, "%3d", mar);
  509.                 PutItemText(wnd, ID_TOPMARGIN, marg);
  510.                 PutItemText(wnd, ID_BOTTOMMARGIN, marg);
  511.             }
  512.             cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
  513.             SendMessage(cwnd, LB_SETSELECTION,
  514.                 CHARSLINE-cfg.LeftMargin, 0);
  515.             cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
  516.             SendMessage(cwnd, LB_SETSELECTION,
  517.                 CHARSLINE-cfg.RightMargin, 0);
  518.             cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
  519.             SendMessage(cwnd, LB_SETSELECTION,
  520.                 LINESPAGE-cfg.TopMargin, 0);
  521.             cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
  522.             SendMessage(cwnd, LB_SETSELECTION,
  523.                 LINESPAGE-cfg.BottomMargin, 0);
  524.             return rtn;
  525.         case COMMAND:
  526.             if ((int) p1 == ID_OK && (int) p2 == 0)    {
  527.                 GetItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort, 4);
  528.                 cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
  529.                 cfg.LeftMargin = CHARSLINE -
  530.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  531.                 cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
  532.                 cfg.RightMargin = CHARSLINE -
  533.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  534.                 cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
  535.                 cfg.TopMargin = LINESPAGE -
  536.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  537.                 cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
  538.                 cfg.BottomMargin = LINESPAGE -
  539.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  540.             }
  541.             break;
  542.         default:
  543.             break;
  544.     }
  545.     return DefaultWndProc(wnd, msg, p1, p2);
  546. }
  547.  
  548. static void FixTabMenu(void)
  549. {
  550.     char *cp = GetCommandText(&MainMenu, ID_TABS);
  551.     if (cp != NULL)    {
  552.         cp = strchr(cp, '(');
  553.         if (cp != NULL)    {
  554.             *(cp+1) = cfg.Tabs + '0';
  555.             if (GetClass(inFocus) == POPDOWNMENU)
  556.                 SendMessage(inFocus, PAINT, 0, 0);
  557.         }
  558.     }
  559. }
  560.  
  561. void PrepFileMenu(void *w, struct Menu *mnu)
  562. {
  563.     WINDOW wnd = w;
  564.     DeactivateCommand(&MainMenu, ID_SAVE);
  565.     DeactivateCommand(&MainMenu, ID_SAVEAS);
  566.     DeactivateCommand(&MainMenu, ID_DELETEFILE);
  567.     DeactivateCommand(&MainMenu, ID_PRINT);
  568.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  569.         if (isMultiLine(wnd))    {
  570.             ActivateCommand(&MainMenu, ID_SAVE);
  571.             ActivateCommand(&MainMenu, ID_SAVEAS);
  572.             ActivateCommand(&MainMenu, ID_DELETEFILE);
  573.             ActivateCommand(&MainMenu, ID_PRINT);
  574.         }
  575.     }
  576. }
  577.  
  578. void PrepSearchMenu(void *w, struct Menu *mnu)
  579. {
  580.     WINDOW wnd = w;
  581.     DeactivateCommand(&MainMenu, ID_SEARCH);
  582.     DeactivateCommand(&MainMenu, ID_REPLACE);
  583.     DeactivateCommand(&MainMenu, ID_SEARCHNEXT);
  584.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  585.         if (isMultiLine(wnd))    {
  586.             ActivateCommand(&MainMenu, ID_SEARCH);
  587.             ActivateCommand(&MainMenu, ID_REPLACE);
  588.             ActivateCommand(&MainMenu, ID_SEARCHNEXT);
  589.         }
  590.     }
  591. }
  592.  
  593. void PrepEditMenu(void *w, struct Menu *mnu)
  594. {
  595.     WINDOW wnd = w;
  596.     DeactivateCommand(&MainMenu, ID_CUT);
  597.     DeactivateCommand(&MainMenu, ID_COPY);
  598.     DeactivateCommand(&MainMenu, ID_CLEAR);
  599.     DeactivateCommand(&MainMenu, ID_DELETETEXT);
  600.     DeactivateCommand(&MainMenu, ID_PARAGRAPH);
  601.     DeactivateCommand(&MainMenu, ID_PASTE);
  602.     DeactivateCommand(&MainMenu, ID_UNDO);
  603.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  604.         if (isMultiLine(wnd))    {
  605.             if (TextBlockMarked(wnd))    {
  606.                 ActivateCommand(&MainMenu, ID_CUT);
  607.                 ActivateCommand(&MainMenu, ID_COPY);
  608.                 ActivateCommand(&MainMenu, ID_CLEAR);
  609.                 ActivateCommand(&MainMenu, ID_DELETETEXT);
  610.             }
  611.             ActivateCommand(&MainMenu, ID_PARAGRAPH);
  612.             if (!TestAttribute(wnd, READONLY) &&
  613.                         Clipboard != NULL)
  614.                 ActivateCommand(&MainMenu, ID_PASTE);
  615.             if (wnd->DeletedText != NULL)
  616.                 ActivateCommand(&MainMenu, ID_UNDO);
  617.         }
  618.     }
  619. }
  620.  
  621.